package models;

import com.fasterxml.jackson.databind.node.ObjectNode;
import play.data.format.Formats;
import play.data.validation.Constraints;
import play.db.ebean.Model;

import javax.persistence.*;

import java.util.*;
import javax.persistence.*;

import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;
import play.libs.Json;

/**
 * Created by richard on 02/04/14.
 */
@Entity
public class Employe  extends Model{
    @Constraints.Required
    String name ;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Date getDateNaissance() {
        return dateNaissance;
    }

    public void setDateNaissance(Date dateNaissance) {
        this.dateNaissance = dateNaissance;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", unique = true, nullable = false)
    int id;
    @Formats.DateTime(pattern="dd/MM/yyyy")
    public Date dateNaissance = new Date();
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public String toString(){
        return this.name;
    }
    /*
    public static Result foo() {
    ArrayNode arrayNode = Json.newObject().putArray("bars");
    arrayNode.add("hello");
    arrayNode.add("world");
    return ok(arrayNode);
}
     */
    public ObjectNode toJson(){
        ObjectNode result = Json.newObject();
        result.put("id",id);
        result.put("name",name);
        result.put("dateNaissance",dateNaissance.toString());
        return result;
    }
    @OneToMany(mappedBy="employe", cascade=CascadeType.REMOVE)
    @OrderBy("dateDebut")
    public List<EvenementAgenda> evenementAgendaList = new ArrayList<EvenementAgenda>();

}
